<template>
  <a-modal title='添加客户结算政策' v-if='modalVisible' :visible='modalVisible' width='650px' :body-style='bodyStyle' @cancel='handleCancel' @ok='handleSubmit'>
    <f-form ref='form' :action='api.bpc' :form-key='this.formItem.policyCustomId' @success='handleCancel'>
      <f-form-item label='单位名称' placeholder='请选择单位名称' name='customName' :readOnly='true' :required='true' :value.sync='formItem.customName' :trigger-change='true'>
        <a-tooltip slot='addonAfter' placement='top' title='点击图标选择单位'>
          <a-icon type='user' style='cursor:pointer' @click='openCustomModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label='结算价' type='number' :precision='3' data-type='number' :required='true' name='settlePrice' :value='formItem.settlePrice' />
      <f-form-item label='结算标准' type='number' tooltip='格式用小数表示,示例值0.18' :precision='3' data-type='number' :required='true'  name='settleRate' :value='formItem.settleRate' />
      <f-form-item label='是否包票' type='radio' name='baopiao' dataType='number' :data='api.busCommon.baopiaoType' :value.sync='formItem.baopiao' />
      <f-form-item label='结算规则' type='radio' name='settleRule' dataType='number' :data='api.busCommon.settleRuleType' :value.sync='formItem.settleRule' />
      <f-form-item label='结算公式' name='settleFormulaId'  type='select' :value='formItem.settleFormulaId' :data='api.formula.list' valueKey='formulaId' label-key='formulaContent' :params='params1' />
      <f-form-item label='开始日期' name='beginDate' type='date' required :value='formItem.beginDate' />
      <f-form-item label='结束日期' name='endDate' type='date' :value='formItem.endDate' />
      <f-form-item label='备注' name='remark' :value='formItem.remark' />
    </f-form>
    <select-hy-custom-modal ref='customModal' @onSelectChange='onSelectCustomChange'></select-hy-custom-modal>
  </a-modal>
</template>
<script>
import api from "../../../../js/api"
import SelectHyCustomModal from "../../../../components/select_hy_custom_modal"

export default {
  name: "policyCustomForm",
  props: {
    policyDrugId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      formModal: false,
      fileIds: [],//上传文件ID
      loaded: false,//是否加载完成
      modalVisible: false,
      params1: {
        formulaType: 3
      },
      bodyStyle: {
        height: "530px",
        overflow: "hidden",
        overflowY: "scroll"
      },
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        policyCustomId: "",
        customId: null,
        bonusAmount: 0,
        baopiao: 1,
        settleRule: 1,
        salePrice: null,
        settlePrice: null,
        settleRate: null,
        settleFormulaId: null,
        beginDate: null,
        endDate: null,
        remark: ""
      }
    },
    openModal(data) {
      this.isEdit = false
      if (data && data.policyCustomId) {
        this.isEdit = true
        this.formItem = data
      } else {
        this.formItem = {}
      }
      this.modalVisible = true
    },
    openCustomModal() {
      this.$refs["customModal"].open()
    },
    onSelectCustomChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "customName": selectedRows[0].customName })
      this.formItem.customName = selectedRows[0].customName
      this.formItem.customCode = selectedRowKeys[0]
    },
    handleCancel() {
      this.modalVisible = false
    },
    //提交表单
    handleSubmit() {
      this.$refs.form.submit({ policyDrugId: this.policyDrugId, customCode: this.formItem.customCode }, () => {
        this.$emit("success")
      })
    }
  },
  created() {
  },
  components: { SelectHyCustomModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
